package trism.game {
	import com.samoiloff.util.data.PropItem;
	/**
	 * @author Samoiloff  http://samoiloff.com/
	 */
	public class FlashVars extends PropItem {
		
		public const WIDTH:int = 760;
		public const HEIGHT:int = 640; 
		
		private const PARTNER_LOGO_LINK	: String = "logos/logo.png";
		private const CONFIG_XML_LINK	: String=  "config.xml";
		private const FONTS_LINK		: String = "fonts.swf";
		
		public var GAME_ID:String;
		public var GAME_RES : String;

		/*
		 * EXTERNAL
		 */
		public var country:String;
		public var language:String;
		
		public var downloadLink : String;
		public var target : String;
		
		public var useCheats : Boolean;
		public var hideDownloadBtns : Boolean;
		
		public var resourcesPath : String;
		public var api : Boolean;
		
		public var gameId : String;
		public var userId : String;
			
		public var configLink:String;
		public var partnerLink:String;
		public var fontsLink:String;
		
		/*
		 * DERIVED
		 */
		
		public var langXmlLink	: String;
		public var logoLink		: String;
		
		public var guestName : String;
		
		public var kongregate : Boolean;
		public var mochi : Boolean;
		
		public function FlashVars() {
			
		}
		
		public function updateFromObj(parameters : Object) : void {
			resourcesPath = parameters.resourcesPath ? parameters.resourcesPath : resourcesPath;
			resourcesPath = resourcesPath ? resourcesPath : '';
			
			language = parameters.language ? parameters.language : language;
			language = language ? language : "en";
			
			country = parameters.country ? parameters.country : country;
			country = country ? country : "US";
			
			downloadLink = parameters.link ? parameters.link : downloadLink;
			downloadLink = downloadLink ? downloadLink : "http://www.alawar.com/download/CropBusters_10105.exe";
			
			target = parameters.target ? parameters.target : target;
			target = target ? target : "_blank";
			
			useCheats = parameters.use_cheats ? parameters.use_cheats == "true" : useCheats;
			
			hideDownloadBtns = parameters.alawar_f ?  parameters.alawar_f == "true" : hideDownloadBtns;
			 
			api = parameters.api ? parameters.api == "true" : api;// ? true: false;
			
			gameId = parameters.game_id ? parameters.game_id : gameId;
			gameId = gameId ? gameId : "virtualFarm";
			
			userId = parameters.user_id ? parameters.user_id : userId;
			userId = userId ? userId : "";
			
			
			updateComplexParams();
		}
		
		public function updateFromXml(xml:XML):void {
			for each (var stringXML:XML in xml.string) {
				switch(String(stringXML.@id)) {
					case "language":		language = stringXML.toString();break;
					case "country":			country = stringXML.toString();break;
					case "link":			downloadLink = stringXML.toString();break;
					case "target":			target = stringXML.toString();break;
					case "use_cheats":		useCheats = stringXML.toString() == "true";break;
					case "alawar_f":		hideDownloadBtns = stringXML.toString() == "true";break;
					case "resources_path": 	resourcesPath = stringXML.toString(); break;
					case "api":				api = stringXML.toString() == "true";break;
					case "game_id":			gameId = stringXML.toString();break;
					case "user_id":			userId = stringXML.toString();break;
				}
			}
			
			updateComplexParams();
		}
		
		private function updateComplexParams():void {
			langXmlLink = resourcesPath + "localized/" + language + "-" + country + "/text/text.xml";
			logoLink = resourcesPath + "localized/" + language + "-" + country + "/images/logo.png";

			configLink = resourcesPath + CONFIG_XML_LINK;
			partnerLink = resourcesPath + PARTNER_LOGO_LINK;
			fontsLink = resourcesPath + FONTS_LINK;
			
			guestName = "Player 1";
		}
		
		
		
	}
}
